/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package main.java.cn.webrx;

import java.io.FileOutputStream;
import java.util.Random;

/**
 * <p>Project: jse2204 - OutputStreamDemo
 * <p>Powered by webrx On 2022-09-22 15:53:05
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class OutputStreamDemo {
    public static void main(String[] args) {
        Random rand = new Random();

        try (var os = new FileOutputStream("my.txt", true)) {
            for (int i = 0; i < 10000; i++) {
                os.write(randStr(rand.nextInt(2, 20)).concat("\r\n").getBytes());
            }
        } catch (Exception e) {

        }

    }

    public static String randStr(int n) {
        Random rand = new Random();
        String letter = "abcdefghijklmnopqrstuvwxyz";
        StringBuilder sbu = new StringBuilder();
        for (int i = 0; i < n; i++) {
            StringBuilder sbu2 = new StringBuilder();
            int len = rand.nextInt(2, 10);
            for (int j = 0; j < len; j++) {
                sbu2.append(letter.charAt(rand.nextInt(letter.length())));
            }
            sbu2.append(" ");
            String ts = sbu2.toString();
            if (i == 0) {
                ts = ts.substring(0, 1).toUpperCase().concat(ts.substring(1));
            } else if (i == n - 1) {
                ts = ts.substring(0, ts.length() - 1) + "!.?".charAt(rand.nextInt(3));
            }
            sbu.append(ts);
        }
        return sbu.toString();
    }
}
